"use strict";
module.exports = {
  /**
   * 分页查询待办进展
   * @url client/todo/kh/getTodoProcessList 前端调用的url参数地址
   * data 请求参数
   * @param {String} params1  参数1
   */
  main: async (event) => {
    let { data = {}, userInfo, util, filterResponse, originalParam } = event;
    let { customUtil, uniID, config, pubFun, vk, db, _, $ } = util;
    let { uid } = data;
    let res = { code: 0, msg: "" };
    // 业务逻辑开始-----------------------------------------------------------
    let { pageIndex, pageSize, todo_id } = data;
    // 参数校验
    if (pageIndex === undefined || pageIndex < 1) {
      return {
        code: -1,
        msg: "pageIndex参数必填且必须大于0",
      };
    }
    if (pageSize === undefined || pageSize < 1 || pageSize > 1000) {
      return {
        code: -1,
        msg: "pageSize参数必填且必须在1-1000之间",
      };
    }
    if (!todo_id) {
      return { code: -1, msg: "缺少待办ID" };
    }
    let info = await vk.baseDao.selects({
      dbName: "dfb-todo-process",
      getCount: true,
      getMain: false,
      pageIndex,
      pageSize,
      sortArr: [
        {
          name: "_add_time",
          type: "desc",
        },
      ],
      whereJson: { todo_id: todo_id },
      // 主表字段显示规则
      fieldJson: {
        todo_id: false,
      },
    });
    if (!info) {
      return { code: 0, msg: "该代办暂无进展", data: [] };
    }
    info.rows.forEach((item) => {
      item.dateTime = item._add_time_str.substring(0, 16);
      delete item._add_time_str;
    });
    res.data = info;
    // 业务逻辑结束-----------------------------------------------------------
    return res;
  },
};
